#ifndef CSUPBR_FILM_H
#define CSUPBR_FILM_H

#include "geometry.h"
#include "texture.h"

#include <string.h>

#include <memory>

namespace csupbr {

    struct Film : Texture {

        inline Film(int width, int height)
            : Texture(width, height, 3, new uint8_t [static_cast<size_t>(width) * height * 3]) {
            memset(_data, 200, sizeof(uint8_t) * static_cast<size_t>(width) * height * channel);
        }

        ~Film() {
            delete[] _data;
        }

        inline void set_pixel(int u, int v, const Vec<float, 3> &pixel) {
            _data[u * channel + channel * width * v] = static_cast<uint8_t>(pixel.r * TO_RGB);
            _data[u * channel + channel * width * v + 1] = static_cast<uint8_t>(pixel.g * TO_RGB);
            _data[u * channel + channel * width * v + 2] = static_cast<uint8_t>(pixel.b * TO_RGB);
        }

        inline const uint8_t *get_data() const { return _data; }

    };

}

#endif // !CSUPBR_FILM_H